import {
  OrderStatusRequest, RepleniShmentMegRequest, OrderSearchRequest
} from '@/api'
export default {
  namespaced: true,
  state: {
    // 组件数据
    PropsData: {
      title: '工单编号：',
      // input框参数
      formLabelAlign: {
        name: '',
        region: '',
        type: ''
      },
      // 内容请求参数
      Order: {
        pageIndex: 1,
        pageSize: 10,
        isRepair: false,
        status: null,
        taskCode: null
      },
      // 下拉菜单
      DropDown: [],
      // 内容数据
      data: [],
      // 页数数据
      TotalPages: {},
      // 当前页数
      num: 1,
      // 下一页是否可点击
      OnClick: true,
      TwClick: true,
      // 工单方式
      RepairOrder: {
        0: '自动',
        1: '手动'
      }
    }
  },
  mutations: {
    // 加
    MaAddnum (state, data) {
      state.PropsData.num++
      state.PropsData.Order.pageIndex++
    },
    // 减
    MaAeenum (state, data) {
      state.PropsData.num--
      state.PropsData.Order.pageIndex--
    },
    // 页数
    MaNum (state, data) {
      state.PropsData.Order.pageIndex = 1
      state.PropsData.num = ''
      state.PropsData.num = 1
      console.log(state.PropsData)
    },
    // 下拉菜单
    MaDropDown (state, data) {
      state.PropsData.DropDown = data
    },
    // 表格内容请求
    MaOrder (state, data) {
      console.log(data)
      state.PropsData.data = data.currentPageRecords || data
      state.PropsData.TotalPages = data
      console.log(data)
      // 生成序列号
      for (let i = 0; i < state.PropsData.data.length; i++) {
        state.PropsData.data[i].number = (i + state.PropsData.num * 10 - 9)
      }
    },
    MaInputFn (state, data) {
      state.PropsData.Order.taskCode = state.PropsData.Order.taskCode.replace(/\D/g, '')
    },
    MaQueryFn (state, data) {
    }
  },
  actions: {
    // 工单状态
    async AcOrderStatus (store, item) {
      const res = await OrderStatusRequest()
      store.commit('MaDropDown', res.data)
    },
    // 售货机详情
    async AcRepleniShmentMeg (store, item) {
      return await RepleniShmentMegRequest(item)
    },
    // 工单请求
    async AcOrderSearch (store, item) {
      const res = await OrderSearchRequest(item)
      store.commit('MaOrder', res.data)
    }
  }
}
